//
//  LAWriteReviewTextTableViewCell.m
//  LYLazizDevelopDemo
//
//  Created by xbn_iMac on 2016/11/4.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LAWriteReviewTextTableViewCell.h"
#import "PlaceholderTextView.h"

@interface LAWriteReviewTextTableViewCell ()

@property (weak, nonatomic) IBOutlet PlaceholderTextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *labNum;
@property (weak, nonatomic) IBOutlet UILabel *labTotleNum;
@property (assign, nonatomic) BOOL isHaveContent;

@end

@implementation LAWriteReviewTextTableViewCell

- (NSString*)getReviewText {
    return self.textView.text;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    if ([LZLanguageManager shareInstance].getLanguageType == LanguageType_Ar) {
        self.labTotleNum.text = @"1000\\";
    }
    else {
        self.labTotleNum.text = @"/1000";
    }
    
    self.labNum.text = @"0";
    
    [self.textView initBaseData];
    self.textView.layer.borderWidth = 0.5;
    self.textView.layer.borderColor = UIColorFromRGB(0xcccccc, 1).CGColor;
    self.textView.layer.cornerRadius = 3;
    // 请写下您的评价，对餐厅改善以及他人用餐的帮助很大呦（输入框提示语，尽量简洁）
    self.textView.placeholder = LZLocalizedString(@"review_text_remind", nil);
    self.textView.placeholderFont=[UIFont systemFontOfSize:14];
    self.textView.placeholderColor=[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
    self.textView.layoutManager.allowsNonContiguousLayout = NO;
    self.textView.tintColor = UIColorFromRGB(0xff7a21, 1);
    
    
    WS(weakSelf);

    [self.textView addMaxTextLengthWithMaxLength:0 andEvent:^(PlaceholderTextView *text) {
        DLog(@"*********%@",text.text);
        if (text.text.length > 1000) {
            text.text = [text.text substringToIndex:1000];
        }
        weakSelf.labNum.text = [NSString stringWithFormat:@"%ld",(unsigned long)text.text.length];
        
        if (weakSelf.isHaveContent != text.text.length) {
            weakSelf.isHaveContent = text.text.length;
            if (weakSelf.haveTextBlock) {
                weakSelf.haveTextBlock(weakSelf.isHaveContent);
            }
        }
    }];
    
    [self.textView addTextViewBeginEvent:^(PlaceholderTextView *text) {
        DLog(@"begin----%@",text.text);
    }];
    
    [self.textView addTextViewEndEvent:^(PlaceholderTextView *text) {
        DLog(@"end----%@",text.text);
    }];
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (CGFloat)cellHeight {
    if (self.labNum.text.length == 0) {
        self.labNum.text = @"0";
    }
    return 174+20+ [self.labNum intrinsicContentSize].height;
}

@end
